var app = getApp();
const DrainageScene = require('../../../../utils/drainage_scene.js')

Component({
  properties: {
    params: {
      type: null
    },
    host :{
      type: null
    }
  },
  data: {
    signdata: {},
    tapnow:true
  }, // 私有数据，可用于模板渲染

  lifetimes: {
    // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
    attached() {
    },
    moved() {},
    detached() {},
  },

  // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
  attached() {

  }, // 此处attached的声明会被lifetimes字段中的声明覆盖
  ready() {
    this.setData({
      signdata: this.data.params,
      tapnow:true
    });
  },

  pageLifetimes: {
    // 组件所在页面的生命周期函数
    show() {},
    hide() {},
    resize() {},
  },

  methods: {
    async signnow() {
      let that = this;
      if(!that.data.tapnow){
        console.log('点击限制！！！');
        return;
      }
      
      let isBindDrainageScene = DrainageScene.bindDrainageScene({
        scene: 4,
        title: `${this.data.signdata.sign_name}`
      });
      if(!isBindDrainageScene) return;//爆客码绑定场景

      that.setData({
        tapnow : false
      });
      let {
        data
      } = await app._postNetWork({
        url: app.getNetAddresss("plugin.sign.Frontend.Modules.Sign.Controllers.sign.sign"),
      })
      if(data.result){
        let signdata = data.data.signdata;
        signdata.text = `已${data.data.sign_name}`;
        let numDate = Number(
          signdata.button_hint.replace(/[^0-9]/gi, "")
        );
        signdata.button_hint = numDate + 1 + "天";
        this.setData({
          signdata: signdata
        });
        //下面这个是h5链接,无法跳装
        let reslink = data.data.success_url;
        app.tips(data.msg);
        setTimeout(() => {
          //要延时执行的代码
          wx.navigateTo({
            url: reslink,
            fail: (err)=>{
              wx.navigateTo({
                url: '/packageA/member/sign/sign',
              })
            }
          })
          
        }, 1500);
      }else{
        wx.showToast({
          icon: 'none',
          title: data.msg,
          duration: 1500
        });
        setTimeout(function() {
          that.setData({
            tapnow : true
          });
        }, 1500); //延迟时间
      }
    }
  }
});
